#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>

using namespace std;

double generateHeight()
{
    return 1.5 + static_cast<double>(rand()) / RAND_MAX * 0.5; // 生成1.5到2.0之间的身高
}
bool generateGender()
{
    return rand() % 2; // 生成0或1，代表女性和男性
}

double generateWeight(double height, bool gender)
{
    double bmi = 18.5 + static_cast<double>(rand()) / RAND_MAX * 3.5 + gender * (0.5 + static_cast<double>(rand()) / RAND_MAX * 1.5); // 生成18.5到22.0之间的BMI
    double plus = 3 + static_cast<double>(rand()) / RAND_MAX * 9;
    return bmi * height * height; // 根据BMI计算体重
}

int main()
{
    srand(static_cast<unsigned>(time(0))); // 设置随机种子
    ofstream outFile("data.txt");

    if (!outFile)
    {
        cerr << "Error opening file for writing." << endl;
        return 1;
    }

    int numberOfData = 1000;

    for (int i = 0; i < numberOfData; ++i)
    {
        double height = generateHeight();
        bool gender = generateGender();
        double weight = generateWeight(height, gender);

        outFile << height << " " << gender << " " << weight << endl;
    }

    outFile.close();
    cout << "Data generated and written to data.txt" << endl;

    return 0;
}
